<template>
  <view class="job-type-popup" v-if="show" @touchmove.stop.prevent>
    <view class="popup-mask" @click="onClose" @touchmove.stop.prevent></view>
    <view class="popup-content" :class="{ 'popup-show': show }" @touchmove.stop>
      <view class="popup-header">
        <text class="popup-title">请先选择工种</text>
        <text class="popup-subtitle">选好工种，平台推荐更多热手</text>
        <view class="close-btn" @click="onClose">×</view>
      </view>
      
      <scroll-view 
        class="job-type-list" 
        scroll-y="true" 
        @touchmove.stop
        :scroll-with-animation="true"
        :show-scrollbar="false"
      >
        <view class="job-type-item" 
          v-for="(item, index) in jobTypes" 
          :key="index"
          @click="selectJobType(index)"
          :class="{ active: selectedIndex === index }">
          <view class="job-type-info">
            <text class="job-type-name">{{item.name}}</text>
            <text class="job-type-desc">{{item.desc}}</text>
          </view>
          <view class="job-type-radio" :class="{ active: selectedIndex === index }">
            <view class="radio-inner" v-if="selectedIndex === index"></view>
          </view>
        </view>
      </scroll-view>
      
      <view class="confirm-btn" @click="onConfirm">确认</view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'JobTypePopup',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    jobTypes: {
      type: Array,
      default: () => []
    },
    initialSelectedIndex: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      selectedIndex: this.initialSelectedIndex
    }
  },
  watch: {
    initialSelectedIndex(val) {
      this.selectedIndex = val;
    },
    show(val) {
      if (val) {
        this.selectedIndex = this.initialSelectedIndex;
      }
    }
  },
  methods: {
    onClose() {
      console.log('关闭工种选择弹窗');
      this.$emit('close');
    },
    selectJobType(index) {
      this.selectedIndex = index;
    },
    onConfirm() {
      console.log('确认选择工种', this.selectedIndex);
      this.$emit('confirm', {
        index: this.selectedIndex,
        jobType: this.jobTypes[this.selectedIndex]
      });
    }
  }
}
</script>

<style lang="scss">
.job-type-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  
  .popup-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
  }
  
  .popup-content {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
    max-height: 80vh;
    
    &.popup-show {
      transform: translateY(0);
    }
    
    .popup-header {
      position: relative;
      padding: 20px 15px 15px;
      text-align: center;
      border-bottom: 1px solid #f0f0f0;
      
      .popup-title {
        font-size: 18px;
        font-weight: bold;
        color: #333;
        display: block;
      }
      
      .popup-subtitle {
        font-size: 12px;
        color: #999;
        margin-top: 5px;
        display: block;
      }
      
      .close-btn {
        position: absolute;
        top: 15px;
        right: 15px;
        width: 24px;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        color: #999;
      }
    }
    
    .job-type-list {
      flex: 1;
      overflow-y: auto;
      padding: 0 15px;
	  box-sizing: border-box;
      max-height: 60vh;
      -webkit-overflow-scrolling: touch;
      
      .job-type-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px;
		box-sizing: border-box;
        border-bottom: 1px solid #f0f0f0;
        border-radius: 8px;
        margin-bottom: 5px;
        
        &.active {
          background-color: #FFF9E6;
          border: 1px solid #FFD000;
          border-bottom: 1px solid #FFD000;
          
          .job-type-name {
            color: #ff9500;
            font-weight: bold;
          }
          
          .job-type-radio {
            border-color: #ff9500;
          }
        }
        
        .job-type-info {
          flex: 1;
          
          .job-type-name {
            font-size: 16px;
            color: #333;
            margin-bottom: 5px;
            display: block;
          }
          
          .job-type-desc {
            font-size: 12px;
            color: #999;
            display: block;
          }
        }
        
        .job-type-radio {
          width: 20px;
          height: 20px;
          border-radius: 50%;
          border: 1px solid #ddd;
          display: flex;
          align-items: center;
          justify-content: center;
          
          .radio-inner {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #ff9500;
          }
        }
      }
    }
    
    .confirm-btn {
      height: 50px;
      line-height: 50px;
      text-align: center;
      background: #ffd000;
      color: #333;
      font-size: 16px;
      font-weight: bold;
    }
  }
}
</style> 